package fy.uap.operatorImpl;

import java.util.Iterator;
import java.util.List;

import com.seeyon.ctp.organization.bo.V3xOrgMember;
import com.seeyon.ctp.organization.bo.V3xOrgPost;

import fy.form.listen.dao.MyOrgManager;
import fy.msg.MessageSender;

public class ProviderMessageManager {

	private long memberID;

	private static long postID = 0L;

	public void setMemberID(long memberID) {
		this.memberID = memberID;
	}

	public boolean checkMemberIDIsExists(String code) {
		if (code != null && !"".equals(code)) {
			return true;
		} else {
			sendMessage("发起人的OA人员信息缺少人员工号，无法写入UAP。");
			return false;
		}
	}

	public void sendMessage(String msg) {
		if (postID == 0) {
			List<com.seeyon.ctp.organization.bo.V3xOrgPost> posts = MyOrgManager
					.getInstance().getAllPosts(5686590792835548528L);
			for (Iterator<V3xOrgPost> iter = posts.iterator(); iter.hasNext();) {
				V3xOrgPost post = iter.next();
				if ("供应商管理系统消息知会".equals(post.getName())) {
					postID = post.getId();
					break;
				}
			}
		}
		List<V3xOrgMember> members = MyOrgManager.getInstance()
				.getMemberByPostID(postID);

		int size = members == null ? 0 : members.size();

		long[] memberIDArray = new long[size + 1];
		for (int i = 0; i < size; i++) {
			memberIDArray[i] = members.get(i).getId();
		}
		memberIDArray[size] = memberID;

		MessageSender.sendMsg(memberIDArray, msg);

	}
}
